package com.sunspring.zdcall.controller.commoncontroller;

import com.sunspring.zdcall.common.SimpleResponse;
import com.sunspring.zdcall.common.constant.enums.StateEnum;
import com.sunspring.zdcall.entity.ZdBaseDepartment;
import com.sunspring.zdcall.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 科室控制层
 * @Author WuLei
 * @Date 2018/11/28  14:51
 */
@RestController
public class DeptController {

    /**
     * 后台地址前缀（经过拦截器）
     */
    private final String backend_prefix = "/sys/dept";

    /**
     * 前端地址前缀（不经过拦截器）
     */
    private final String front_prefix = "/dept";

    @Autowired
    private DeptService deptService;

    /**
     * 查询所有科室信息
     */
    @GetMapping(backend_prefix + "/info")
    public SimpleResponse info() {
        return SimpleResponse.success(deptService.getSelective(new ZdBaseDepartment()));
    }

    /**
     * 查询所有已启用科室信息
     */
    @GetMapping(front_prefix + "/infoAct")
    public SimpleResponse infoAct() {
        ZdBaseDepartment department = new ZdBaseDepartment();
        department.setDepartmentState(StateEnum.enable.getCode());
        return SimpleResponse.success(deptService.getSelective(department));
    }

    /**
     * 根据科室ID删除科室信息
     * @param deptId 科室Id
     */
    @PostMapping(backend_prefix + "/delete")
    public SimpleResponse delete(String deptId){
        deptService.deleteDept(deptId);
        return SimpleResponse.success();
    }

    /**
     * 根据科室ID修改科室信息
     * @param departmentInfo 科室信息
     */
    @PostMapping(backend_prefix + "/update")
    public SimpleResponse update(ZdBaseDepartment departmentInfo){
        deptService.update(departmentInfo);
        return SimpleResponse.success();
    }

    /**
     * 启用/停用科室
     * @param deptId 科室ID
     */
    @PostMapping(backend_prefix + "/switch")
    public SimpleResponse switchDept(String deptId){
        deptService.switchDept(deptId);
        return SimpleResponse.success();
    }


}
